#ifndef ADM_FRAMEBUFFER_H_
#define ADM_FRAMEBUFFER_H_
#include <iostream>
#include "adm_svpng.h"
#include "adm_header.h"

using namespace std;

namespace Andromeda {
  class FrameBufferPNG {
    public : 
      FrameBufferPNG( unsigned int width, unsigned height, char* fileName) {
        int size_color;
        height_   = height;
        width_    = width;
        fileName_ = fileName;
        size_color = height_ * width_ * 4;
        rgba = new unsigned char[size_color];
      }
      ~FrameBufferPNG() {
        delete[] rgba;
      }
      void Pixel (int x_loc, int y_loc, unsigned char r, unsigned char g, unsigned char b, unsigned char a ) {
        int loc;
        loc = (y_loc * width_ + x_loc)*4;
        rgba[loc ++] = r;
        rgba[loc ++] = g;
        rgba[loc ++] = b;
        rgba[loc ++] = a;
      }
      void OutputFile(){
        FILE* fp;
        fp = fopen (fileName_, "wb");
        if (fp != NULL) {
          svpng(fp, width_, height_, rgba, 1);
          fclose(fp); 
        } else {
          cout<<"Fail to open the file :"<<fileName_ <<endl;
        }
      }
      
    private :
      unsigned int height_ ;
      unsigned int width_  ;
      char* fileName_;
      unsigned char* rgba;


  };


}

#endif
